🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / database / src / commonMain / kotlin / org / meshtastic / core / database / DeviceIdentity.kt
Displaying Raw • Download
core/database/src/commonMain/kotlin/org/meshtastic/core/database/DeviceIdentity.kt d5848ad5e02bd9b5b1726bedfa51ceb0faaa0240 (d5848ad5) Text, 2.99 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.database
Tff7b72import T7ee787androidx.datastore.preferences.core.Preferences
Tff7b72import T7ee787androidx.datastore.preferences.core.stringPreferencesKey
Tff7b72import T7ee787okio.ByteString.Companion.encodeUtf8
Tff7b72import T7ee787org.meshtastic.core.database.entity.MyNodeEntity
T8b949e/** Ingestion hex-encodes the 16-byte `device_id`; require that shape so lossy legacy values can't be compared. */
Tff7b72private Tff7b72val Te6edf3HEX_DEVICE_ID Tff7b72= Te6edf3RegexTb4b4b4(Ta5d6ff"Ta5d6ff[0-9a-fA-F]{16,64}Ta5d6ff"Tb4b4b4)
T8b949e/**
* A device id usable for hardware-identity comparison; null when absent, blank, the legacy placeholder, or not in the
* hex form current ingestion produces (older app versions persisted a lossy utf8 decode of the raw bytes — those values
* can collide across devices, so they are treated as absent rather than compared). The id is the factory-burned silicon
* identifier from `MyNodeInfo.device_id` — stable across firmware upgrades, erases, and key changes — but not reported
* by all hardware (e.g. classic ESP32) and deliberately zeroed for unauthenticated clients in lockdown mode, so callers
* must always tolerate null.
*/
Tff7b72internal Tff7b72fun Td2a8ffvalidDeviceIdOrNullTb4b4b4(Te6edf3idTb4b4b4: Tffa657String?Tb4b4b4)Tb4b4b4: Tffa657String? Tff7b72=
Te6edf3idTff7b72?.Te6edf3takeIf Tb4b4b4{ Tffa657it Tff7b72!Tff7b72= Te6edf3MyNodeEntityTb4b4b4.Te6edf3DEVICE_ID_UNKNOWN Tff7b72&Tff7b72& Tffa657itTb4b4b4.Te6edf3matchesTb4b4b4(Te6edf3HEX_DEVICE_IDTb4b4b4) Tb4b4b4}
T8b949e/** Datastore key mapping a node number to its canonical DB. Legacy: node numbers renumber under firmware 2.8. */
Tff7b72internal Tff7b72fun Td2a8ffnodeDbPrefKeyTb4b4b4(Te6edf3nodeNumTb4b4b4: Tffa657IntTb4b4b4)Tb4b4b4: Te6edf3PreferencesTb4b4b4.Te6edf3KeyTff7b72<Tffa657StringTff7b72> Tff7b72=
Te6edf3stringPreferencesKeyTb4b4b4(Ta5d6ff"Tffd700${Te6edf3DatabaseConstantsTb4b4b4.Te6edf3NODE_DB_FOR_PREFIXTffd700}Tffd700$Te6edf3nodeNumTa5d6ff"Tb4b4b4)
T8b949e/**
* Datastore key mapping a factory-burned device id to its canonical DB. The id is hex-encoded: it originates as raw
* hardware bytes decoded lossily into a string, so normalize to printable key material.
*/
Tff7b72internal Tff7b72fun Td2a8ffdeviceDbPrefKeyTb4b4b4(Te6edf3deviceIdTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3PreferencesTb4b4b4.Te6edf3KeyTff7b72<Tffa657StringTff7b72> Tff7b72=
Te6edf3stringPreferencesKeyTb4b4b4(Ta5d6ff"Tffd700${Te6edf3DatabaseConstantsTb4b4b4.Te6edf3DEVICE_DB_FOR_PREFIXTffd700}Tffd700${Te6edf3deviceIdTb4b4b4.Te6edf3encodeUtf8Tb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3hexTb4b4b4(Tb4b4b4)Tffd700}Ta5d6ff"Tb4b4b4)
T8b949e/**
* Resolves which canonical DB the connected device already claimed: the hardware-stable device-id claim wins, the
* node-number claim is the fallback for hardware without a device id and for claims written by older app versions.
*/
Tff7b72internal Tff7b72fun Td2a8ffresolveDbClaimTb4b4b4(
Te6edf3prefsTb4b4b4: Te6edf3PreferencesTb4b4b4,
Te6edf3deviceKeyTb4b4b4: Te6edf3PreferencesTb4b4b4.Te6edf3KeyTff7b72<Tffa657StringTff7b72>Tff7b72?Tb4b4b4,
Te6edf3nodeKeyTb4b4b4: Te6edf3PreferencesTb4b4b4.Te6edf3KeyTff7b72<Tffa657StringTff7b72>Tb4b4b4,
Tb4b4b4)Tb4b4b4: Tffa657String? Tff7b72= Te6edf3deviceKeyTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3prefsTff7b72[Tffa657itTff7b72] Tb4b4b4} Tff7b72?: Te6edf3prefsTff7b72[Te6edf3nodeKeyTff7b72]
Served by rngit 1.5.0 - Generated in 0.05s